package com.sunriz.ctrl.server.utils.scada;

import com.sunriz.ctrl.views.ScadaController;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.util.Duration;

/**
 * ClassName: Timer
 * Package: com.sunriz.ctrl.server.utils.scada
 * Description:
 *
 * @Author BuTang
 * @Create 2025/1/20 16:14
 * @Version 1.0
 */
public class Timer  {
    private static Timeline timeline;

    // 启动更新表格的定时任务
    public static void startUpdatingTable() {
        // 创建一个Timeline，每隔1秒更新一次表格
        timeline = new Timeline(
                new KeyFrame(Duration.seconds(1), event -> {
                    // 每秒更新一次表格数据
                    ScadaController.createTableView();
                })
        );

        // 设置为无限循环
        timeline.setCycleCount(Timeline.INDEFINITE);
        timeline.play();
    }

    // 停止定时任务
    public static void stopUpdatingTable() {
        if (timeline != null) {
            timeline.stop();
            System.out.println("定时任务已停止");
        }
    }
}
